<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-input
        placeholder="请输入内容"
        v-model="queryInfo.query"
        style="width:350px"
        clearable
      >
        <el-button
          slot="append"
          icon="el-icon-search"
          @click="OrdersList()"
        ></el-button>
      </el-input>

      <template>
        <el-table
          :data="ordersList"
          border
          style="width: 100% ;margin-top:15px"
        >
          <el-table-column type="index"></el-table-column>
          <el-table-column
            prop="order_number"
            label="订单编号"
            width="220px"
          >
          </el-table-column>
          <el-table-column
            prop="order_price"
            label="订单价格"
            width="100px"
          >
          </el-table-column>
          <el-table-column
            prop="pay_status"
            label="是否付款"
            width="100px"
          >
            <template slot-scope="scope">
              <el-tag
                type="danger"
                v-if="scope.row.pay_status==='0'"
              >未付款</el-tag>
              <el-tag
                type="success"
                v-else-if="scope.row.pay_status==='1'"
              >已付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            prop="is_send"
            label="是否发货"
            width="100px"
          >
          </el-table-column>
          <el-table-column
            prop="create_time"
            label="下单时间"
          >
            <template slot-scope="scope">
              {{scope.row.create_time | dateFormat}}
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            width="160px"
          >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="dialogVisible=true"
            ></el-button>
            <el-button
              size="mini"
              type="success"
              icon="el-icon-location"
              @click="wuliujindu()"
            ></el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <!-- 修改地址 -->
      <el-dialog
        title="修改地址"
        :visible.sync="dialogVisible"
        width="50%"
        @close="closedDUIHUA"
      >
        <span
          slot="footer"
          class="dialog-footer"
        >
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item
              label="省市区/县"
              prop="shengshiqu"
            >
              <el-cascader
                size="large"
                :options="options"
                v-model="selectedOptions"
                @change="handleChange"
                clearable
              >
              </el-cascader>

            </el-form-item>
            <el-form-item
              label="详细地址"
              prop="addres"
            >
              <el-input v-model="ruleForm.addres"></el-input>
            </el-form-item>
          </el-form>
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button
            type="primary"
            @click="biaodanyanzheng()"
          >确 定</el-button>
        </span>
      </el-dialog>

      <!-- 物流进度 -->
      <el-dialog
        title="物流进度"
        :visible.sync="dialogVisibles"
        width="50%"
      >
        <span>物流信息</span>
      </el-dialog>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
import { regionData, CodeToText } from "element-china-area-data";
export default {
  data() {
    return {
      ordersList: [],
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5,
      },
      ruleForm: {
        addres: "",
        shengshiqu: "",
      },
      rules: {
        shengshiqu: [
          { required: true, message: "请选择省区市/县", trigger: "blur" },
        ],
        addres: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
      total: 0,
      dialogVisible: false,
      dialogVisibles: false,
      options: regionData,
      selectedOptions: [],
    };
  },
  created() {
    this.OrdersList();
  },
  methods: {
    //获取订单列表
    async OrdersList() {
      const res = await this.$http.get("orders", { params: this.queryInfo, });
      console.log(123);
      console.log(res.data.data);
      this.ordersList = res.data.data.goods;
      // console.log(this.ordersList);
      this.total = res.data.data.total;
    },
    //分页
    handleSizeChange(val) {
      this.queryInfo.pagesize = val;
      this.OrdersList();
      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val;
      this.OrdersList();
      // console.log(`当前页: ${val}`);
    },
    //城市选择框
    handleChange() {
      var loc = "";
      for (let i = 0; i < this.selectedOptions.length; i++) {
        loc += CodeToText[this.selectedOptions[i]];
      }
      console.log(loc);

      this.ruleForm.shengshiqu = loc;
    },
    //表单验证
    biaodanyanzheng() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.$message.success("修改地址成功");
          this.dialogVisible = false;
        } else {
          this.$message.error("请填写信息！！！");
        }
      });
    },
    //关闭清空对话框
    closedDUIHUA() {
      this.$refs.ruleForm.resetFields();
    },
    //物流进度
  async wuliujindu() {
      this.dialogVisibles = true;

    // const res =await this.$http.get(`/kuaidi/1106975712662`)

    // console.log(res.data);
    },
  },
};
</script>

<style scoped>
.el-card {
  margin-top: 15px;
}
.el-pagination {
  margin-top: 15px;
}
.el-cascader {
  width: 100%;
}
</style>
